package com.example.airport.parent;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.StrictMode;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.administrator.dialoglibrary.ConfirmDialog;
import com.example.airport.R;
import com.example.airport.data.Book;
import com.example.airport.data.BookAdapter;
import com.example.airport.data.FixedSizeLinkedList;
import com.example.airport.net.G;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;
import com.shawnlin.preferencesmanager.PreferencesManager;

import java.util.HashMap;
import java.util.Vector;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.everything.android.ui.overscroll.OverScrollDecoratorHelper;

public class FatherActivity extends AppCompatActivity {

    public int model=0;  //当前模式: 0：ai 模式  1：人工模式  在ConfigActivity中会用到

    /**
     * 语音播报
     */
    protected SpeechSynthesizer mTts;
    private String voicer = "xiaoyan";
    private String mEngineType = SpeechConstant.TYPE_CLOUD;
    private Vector<byte[]> container = new Vector<>();


    public Typeface iconFont, iconFont1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        preferenceInit();
        mTts = SpeechSynthesizer.createSynthesizer(this, mTtsInitListener);

}

    /**

     合成回调监听。
     */


    protected InitListener mTtsInitListener = new InitListener() {
        @Override

        public void onInit(int code) {
            Log.i("TAG", "InitListener init() code = " + code);

            if (code != ErrorCode.SUCCESS) {
                //showTip("初始化失败,错误码：" + code);

            } else {
               // showTip("初始化成功");

            }

        }

    };

    /**
     * 参数设置初始化
     */
    void preferenceInit() {
        new PreferencesManager(this)
                .setName("flag")
                .init();

    }

    private View statusBarView;
    public void setStatusBarView() {
        if (Build.VERSION.SDK_INT >= 21) {
            //延时加载数据，保证Statusbar绘制完成后再findview。
            Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
                @Override
                public boolean queueIdle() {
                    initStatusBar();
                    //不加监听,也能实现改变statusbar颜色的效果。但是会出现问题：比如弹软键盘后,弹popwindow后,引起window状态改变时,statusbar的颜色就会复原.
                    getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                        @Override
                        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                            initStatusBar();
//                        getWindow().getDecorView().removeOnLayoutChangeListener(this);
                        }
                    });

                    //只走一次
                    return false;
                }
            }); }
    }



    public Toolbar toolbar;
    protected void toolbarInit() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        setSupportActionBar(toolbar);
       // toolbar.setTitle("标题");
        toolbar.setNavigationOnClickListener((e) -> {
            finish();
        });

    }


    public void initToolbar()
    {
        toolbarInit();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationIcon(R.mipmap.left);
    }



    /**
     * 颜色渐变
     */
    private void initStatusBar() {
        if (statusBarView == null) {
            //利用反射机制修改状态栏背景
            int identifier = getResources().getIdentifier("statusBarBackground", "id", "android");
            statusBarView = getWindow().findViewById(identifier);
        }

        if (statusBarView != null) {
            statusBarView.setBackgroundResource(R.drawable.bg_title);
        } else {
//            Log.w( "base","statusBarView is null.");
        }
    }


    /**
     * 设置iconfont
     */
//    void iconfontSetting() {
//        iconFont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
//        iconFont1 = Typeface.createFromAsset(getAssets(), "iconfont1.ttf");
//    }










}
